package _interview150;

import _object.ListNode;

/**
 * 61. 旋转链表
 */
public class No61 {
    public ListNode rotateRight(ListNode head, int k) {
        if (head == null || head.next == null) return head;
        ListNode p0 = head;
        int len = 1;
        while (p0.next != null) {
            len++;
            p0 = p0.next;
        }
        p0.next = head;

        for (int i = 0; i < len - k % len; i++) {
            p0 = p0.next;
        }

        ListNode ans = p0.next;
        p0.next = null;

        return ans;
    }
}
